/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager.create;

import br.com.foxline.model.Configuracao;
import br.com.foxline.model.Parametro;
import br.com.foxline.service.ConfiguracaoService;
import br.com.foxline.util.Msg;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author luciano
 */
@ManagedBean
@ViewScoped
public class ManagerConfiguracao implements Serializable {

    private Configuracao config;
    @EJB
    private ConfiguracaoService configuracaoService;

    @PostConstruct
    public void init() {
        config = configuracaoService.getConfig();
    }
    
    public void add() {
        config.getParametros().add(new Parametro());
    }

    public void salvar() {
        if (config.getId() == null) {
            configuracaoService.save(config);
        } else {
            configuracaoService.update(config);
        }
        
        Msg.messagemInfo(Msg.SuccessFull);
    }

    public Configuracao getConfig() {
        return config;
    }
    
    public void remove(Parametro parametro){
        config.getParametros().remove(parametro);
    }

    public void setConfig(Configuracao config) {
        this.config = config;
    }

}
